//
//  SpecialDetailTableViewController.m
//  WisdomZhuHai
//
//  Created by yewei on 14/10/27.
//  Copyright (c) 2014年 wyd. All rights reserved.
//

#import "SpecialDetailTableViewController.h"
#import "UIImageView+WebCache.h"
#import "Common.h"

@interface SpecialDetailTableViewController ()

@end

@implementation SpecialDetailTableViewController

const float CELL_HEIGHT = 96;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.1)];
    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.tableView.bounds.size.width, 0)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self setEnableRefresh:YES];
    [self setEnableLoadMore:YES];
    self.pullTableViewDelegate = self;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [self.titles count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CELL_HEIGHT;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellMessage";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    // Configure the cell...
    if(cell == nil)
    {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CellMessage"  owner:self options:nil] lastObject];
    }
    UIImageView *imgView = (UIImageView *)[cell viewWithTag:1000];
    NSString *imgUrl = [self.iconPaths objectAtIndex:indexPath.row];
    [imgView setImageWithURL:[Common getFullDownloadPathByRelativePath:imgUrl] placeholderImage:nil];
    NSString *title = [self.titles objectAtIndex:indexPath.row];
    UITextView *textView = (UITextView *)[cell viewWithTag:1001];
    textView.text = title;
    textView.font =[UIFont systemFontOfSize:15.0];
    UILabel *label = (UILabel *)[cell viewWithTag:1002];
    NSString *subTitle = [self.subTitles objectAtIndex:indexPath.row];
    label.text = subTitle;
    label = (UILabel *)[cell viewWithTag:1003];
    NSString *time = [self.times objectAtIndex:indexPath.row];
    label.text = time;
    //时钟
    UIImageView *clockView = (UIImageView *)[cell viewWithTag:1004];
    clockView.image = [UIImage imageNamed:@"Information/Clock.png"];
    return cell;
}


#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *url = [self.urls objectAtIndex:indexPath.row];
    WebIOS *web = [[WebIOS alloc]initWithFrame:self.view.bounds url:[Common getUrlByString:url]];
//     NSString *name = [self.titles objectAtIndex:indexPath.row];
//    web.title = name;
    [self.nvControl pushViewController:web animated:YES];
    if(self.nvControl == nil)
    {
        NSLog(@"specialDetailTableView nvControl is nil")
    }
}

- (void)resetPullTableViewState
{
    [self setPullTableIsRefreshing:NO];
    [self setPullTableIsLoadMore:NO];
}

#pragma mark - PullTableViewDelegate
- (void)pullTableViewDidTriggerRefresh:(PullTableView*)pullTableView
{
    //下拉刷新
    if(self.specialDelegate && [self.specialDelegate respondsToSelector:@selector(specialDetailTableViewDidTriggerRefresh:)])
    {
        [self.specialDelegate specialDetailTableViewDidTriggerRefresh:self];
    }
}

-(void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView
{
    //加载更多
    if(self.specialDelegate && [self.specialDelegate respondsToSelector:@selector(specialDetailTableViewDidLoadMore:)])
    {
        [self.specialDelegate specialDetailTableViewDidLoadMore:self];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
